﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SnmpForm.ApBatchConfig
{
    public partial class ucLoginPasswd : UserControl
    {
        public ucLoginPasswd()
        {
            InitializeComponent();
        }

        public string GetUsername()
        {
            return textBoxUsername.Text;
        }

        public string GetPasswd()
        {
            return textBoxPasswd.Text;
        }

        public string GetComfirmPasswd()
        {
            return textBoxConfirmPasswd.Text;
        }

        public bool CheckInput()
        {
            bool bValid = false;
            labelError.Text = "";
            string username = GetUsername() ;
            string password =GetPasswd();
            string confirm = GetComfirmPasswd();
            if (username.Length > 0)
            {
                //用户名是否含有非法字符
                bValid =
                    System.Text.RegularExpressions.Regex.IsMatch(username, @"^[a-zA-Z0-9]+$");
                if (bValid)
                {
                    if (password.Length > 0)
                    {

                        if (password.Equals(confirm))
                        {
                            //密码是否含有非法字符
                            bValid =
                                System.Text.RegularExpressions.Regex.IsMatch(
                                                            password,
                                                            @"^[a-zA-Z0-9]+$");
                            if (bValid)
                            {
                            }
                            else
                            {
                                labelError.Text = "密码含有非法字符";
                            }
                        }
                        else
                        {
                            bValid = false;
                            labelError.Text = "两次输入的密码不相同";
                        }
                    }
                    else
                    {
                        bValid = false;
                        labelError.Text = "请输入密码";
                    }
                }
                else
                {
                    bValid = false;
                    labelError.Text = "用户名含有非法字符";
                }
            }
            else
            {
                bValid = false;
                labelError.Text = "请输入用户名";
            }
            return bValid;
        }
    }
}
